Assignemnt #58 and 56th program
Code
///Name: Derrick Andreasen
///Period: 7
///Program name: 56th Program
///File name: Fift6Prog.java
///Date Finished:11/10/2015
import java.util.Random;
import java.util.Scanner;
public class Fift6Prog
{
public static void main( String[] args )
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int x, number;
System.out.println( "I'm thinking of a number between 1-100. Try to guess it." );
System.out.print( "> " );
number = keyboard.nextInt();
System.out.println( "" );
x = 1 + r.nextInt(100);
if(number == x )
{
System.out.println( "You guessed it! What are the odds?!" );
System.out.println( "" );
}
else if(number <= x)
{
System.out.println( "Sorry, you are too low. I was thinking of " + x + ".");
System.out.println( "" );
}
else if(number >= x)
{
System.out.println( "Sorry, you are too high. I was thinking of " + x + "." );
System.out.println( "" );
}
}
}
Picture of the output